package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.db.BlackList;
import com.tanhua.db.UserInfo;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.vo.PageResult;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @version 1.0
 * @author： xtr
 * @date： 2021-03-07 20:52
 */
@Service
public class PageResultApiImpl implements PageResultApi {
    @Autowired
    private BlackListMapper blackListMapper;
    /**
     * 分页查询黑名单
     *
     * @param page
     * @param pagesize
     * @param userId
     * @return
     */
    @Override
    public PageResult findBlackList(long page, long pagesize, Long userId) {
        //构建page对象
        IPage<UserInfo> userInfoPage = new Page<>();
        //查询
        IPage<UserInfo> iPage = blackListMapper.findBlackList(userInfoPage,userId);
        //构建pageresult对象
        PageResult pageResult = new PageResult();
        //总记录数
        pageResult.setCounts(iPage.getTotal());
        pageResult.setPages(iPage.getPages());
        pageResult.setPagesize(pagesize);
        //分页结果集
        pageResult.setItems(iPage.getRecords());
        //当前页
        pageResult.setPage(page);
        return pageResult;
    }

    /**
     * 删除黑名单
     *
     * @param uid    要删除的黑名单用户id  black_user_id
     * @param userId
     */
    @Override
    public void deleteBlackList(long uid, Long userId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("black_user_id",uid);
        blackListMapper.delete(queryWrapper);
    }

}
